//
//  ST_QuickMessageTextViewModel.swift
//  btvideo
//
//  Created by mac on 2021/9/8.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import Foundation
import RxSwift
import RxCocoa

class ST_QuickMessageTextViewModel {
    
    /// 快捷搭讪文字内容
    let content = BehaviorRelay<String>(value: "")
    
    /// 添加常用户
    /// - Returns: Single
    func add() -> Single<Void> {
        
        guard !content.value.isEmpty else {
            return Single.error(ST_MyError.description("请输入您要添加的常用语"))
        }
        
        return
            Single.create { [weak self] single in
                JVrequest(PH.addQuickMessageListApi, parameters: ["content": self?.content.value ?? "",
                                                                  "type": QuickMessageCategory.text.rawValue]) { json in
                    single(.success(()))
                } failure: { (code, error) in
                    single(.failure(ST_MyError.description(error)))
                }
                
                return Disposables.create()
            }
        
    }
}
